/*
 * Alberto Ruiz-Larrea Guillén...11383
 * Erdi Dogruel..................14955
 * Marcos Pérez Martín...........10324
 */

package com.example.database;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.widget.TextView;

//This class puts every player of a team in a string, and the string in a textview
public class getTeamPlayers extends AsyncTask<OpenDB, Integer, String> {

	TextView text;
	String team;

	public getTeamPlayers(TextView t, String te) {
		text = t;
		team = te;
	}

	@Override
	protected String doInBackground(OpenDB... params) {
		OpenDB db = params[0];
		SQLiteDatabase watch = db.getReadableDatabase();
		String[] columns = new String[] { OpenDB.id, OpenDB.name,
				OpenDB.position, OpenDB.team, OpenDB.rating };
		Cursor cursor = watch.query(OpenDB.table2, columns, OpenDB.team + "=?",
				new String[] { team }, null, null, null);

		StringBuffer res = new StringBuffer("");
		cursor.moveToFirst();
		while (!cursor.isAfterLast()) {
			res.append(cursor.getString(1));
			res.append(',');
			res.append(cursor.getString(2));
			res.append(',');
			res.append(cursor.getInt(4));
			res.append('\n');
			cursor.moveToNext();
		}
		cursor.close();
		return res.toString();
	}

	@Override
	protected void onPostExecute(String result) {
		text.setText(result.toString());
	}
}